<?php

/**
 * Trader form.
 *
 * @package    truetrader
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class TraderForm extends BaseTraderForm
{

  public function configure()
  {
    $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('form');

    $this->useFields(array(
        'character_id', 'sex_id', 'birthday', 'country', 'city_code', 'picture', 'phone', 'mobile_phone', 'skype_address',
        'personnal_description', 'job', 'asset', 'started', 'weekly_hour', 'follower_access_id', 'follow_credit'
    ));

    /*unset(
            $this['user_id'], $this['username'],
            $this['follower_count'], $this['followed_count'],
            $this['leaver_count'], $this['credit'],
            $this['created_at'], $this['updated_at']
    );*/


    $this->widgetSchema['picture'] = new sfWidgetFormInputFile(array());
    $this->setValidator('picture', new sfValidatorFile(array(
    'mime_types' => 'web_images',
        'required' => false,
    'path' => sfConfig::get('sf_upload_dir').'/traders',
  )));


    $this_year = intval(date('Y', time()));
    $years = range(1900, $this_year);
    $this->widgetSchema['birthday'] = new sfWidgetFormI18nDate(array(
                'culture' => $this->getCurrentCulture(),
                'years' => array_combine($years, $years)
            ));

    $years = range(1950, $this_year);
    $this->widgetSchema['started'] = new sfWidgetFormI18nDate(array(
                'culture' => $this->getCurrentCulture(),
                'years' => array_combine($years, $years),
                'format' => '%year%'
            ));

    $this->widgetSchema['country'] = new sfWidgetFormI18nChoiceCountry(array('default' => 'FR'));

    $this->widgetSchema['follower_access_id'] = new sfWidgetFormDoctrineChoice(array(
        'model' => $this->getRelatedModelName('FollowerAccess'), 
        'table_method' => 'selectAccess',
        'add_empty' => false));
  }

  public function getCurrentCulture()
  {
    return isset($this->options['culture']) ? $this->options['culture'] : 'en';
  }

}
